#include "widget.h"
#include "./ui_widget.h"

Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);
    setMouseTracking(true);
}

Widget::~Widget()
{
    delete ui;
}

void Widget::mousePressEvent(QMouseEvent *event)
{
    // if(event->button()==Qt::LeftButton){
    //     qDebug()<<"pressed left button";
    // }

    // if(event->button()==Qt::RightButton){
    //     qDebug()<<"pressed right button";
    // }

    if(event->button()==Qt::MiddleButton){
        qDebug()<<"pressed middle button";
    }
}

void Widget::mouseReleaseEvent(QMouseEvent *event)
{
    if(event->button()==Qt::LeftButton){
        qDebug()<<"左键释放";
    }
}

void Widget::mouseDoubleClickEvent(QMouseEvent *event)
{

    if(event->button()==Qt::LeftButton){
        qDebug()<<"左键双击";
    }
    if(event->button()==Qt::RightButton){
        qDebug()<<"右键双击";
    }
    if(event->button()==Qt::MiddleButton){
        qDebug()<<"中键双击";
    }
}

void Widget::mouseMoveEvent(QMouseEvent *event)
{
    qDebug()<<"鼠标移动到："<<event->pos();
}

#include <QWheelEvent>
#include <QDebug>

void Widget::wheelEvent(QWheelEvent *event)
{
    static int x = 0;
    // 使用 angleDelta 方法代替 delta 方法
    const int delta = event->angleDelta().y(); // 获取滚轮的垂直移动量

    x += delta; //±120

    if(delta > 0)
    {
        qDebug() << "滚轮往前" << x;
    }
    else
    {
        qDebug() << "滚轮往后" << x;
    }
}
